if (!$.cookie('token')) {
    window.location.href = './shopunknwo.html'
}

class Book extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            thumbPicPath: '',
            name:'',
            kc:'',
             labels:-1,
             val:'',
             state:1,
             scid:-1,
            publishhouse:'',
            author:'',
            orders:1,
            describe:'',
            code:'',
            unit:'',
            isnew: GetQueryString('isnew') == 0,
            bollowed: 0,
            filecode: 0,  //0封面图 1详情图 2轮播图
            id: 0,
            finishupload: !1,
            uploadword: '上传',
            btntypehtml:[],
            btnchecklist:[],
            imglist: [],
            detailimg: [],
            detaillist: [], //存的是base64数组
            swiperimg: [],
            swiperimglist: []//存的是base64数组
            ,pagesize:10000,
            awards:-1,
            masters:-1,
            start:0,
            lid:'',
            isrecommend:0,
            agefrom:0,
             ageto:0,
             PICS:'',
            ismember:"F",
            lbimgsrc: '',
            lbfileimgshow: !0,
            lbimgstate: '',
            // lbhtml:[],
            lbimgsrcarr: [],
            fileimgshow: !0,
            imgstate: '',
            imgsrc: '',
            isbn10:'',
            isbn13:'',
        };
    }

    // 排序
    // toorder(id){
    //     let {ishide} = this.state;
    //     $('#ishide'+id).toggle();
    //     console.log(ishide,'hide');
    //     this.setState({ishide});
    //     $("#"+id).val('');
    // }
    // setcategoryorder(id){
    //     let order = $("#"+id).val(),data;
    
    //     if(isNaN(order)||order<1||order>999){
    //         alert('请输入1-999的正整数');
    //         return;
    //     }
    //     order = Math.floor(order);
    //    data={id,order};
    //     myiconsetorder(data,res=>{
    //         if(res.issuccess==1){
    //             console.log("设置成功");
    //         }
    //     });

    // }

    getbook(){
       
        // var id = GetQueryString("id");
            // if (id != '0' && id != "null") {
              
                // this.state.id = id;
                
                var {id} = this.state,that=this;
                console.log(id,'idididididi');
                
                findbooksbyids(id, res => {
                    if (res.issuccess == 1) {
                        let x=res.data
                        // var goods = res.list;
                        // goods.forEach((x,i)=>{
                            // if(x.id ==id){
                                let {bollowed,state,isrecommend,ismember,labels,imgsrc,code}=that.state,labelsarr=x.labels.split(","),lbhtml = [], lbimgsrcarr = []
                                if(labelsarr.length!=0){
                                    labels=labelsarr[0]
                                }
                                if(x.thumbPicPath.indexOf('http')==-1){
                                    imgsrc = `${API_HEAD}imgs/${x.thumbPicPath}`
                                }else{
                                    imgsrc =x.thumbPicPath
                                }
                                if(x.detaillist!=''&&x.detaillist!=null){
                                    let lbimgarr = x.detaillist.split(",")
                                    lbimgarr.forEach((y, i) => {
                                        let j = `${API_HEAD}imgs/${y}`
                                        lbimgsrcarr.push(j)
                                    })
                                    lbimgsrcarr.forEach((x, i) => {
                                        lbhtml.push(
                                            <div className="img_warp">
                                                <img src={x} className="img" />
                                                <img className='closeimg' onClick={this.del_lbimg.bind(this, i, x)} src='./src/img_close.png' />
                                            </div>
                                        )
                                    })
                                    that.setState({lbfileimgshow: !1,lbhtml, lbimgsrcarr})
                                }
                                bollowed=x.bollowed
                                state=x.state
                                isrecommend=x.isrecommend
                                ismember=x.ismember
                                $(`input[name='bollowed'][value=${bollowed}]`).prop("checked", "checked");
                                $(`input[name='state'][value=${state}]`).prop("checked", "checked");
                                $(`input[name='isrecommend'][value=${isrecommend}]`).prop("checked", "checked");
                                $(`input[name='ismember'][value=${ismember}]`).prop("checked", "checked");
                                if(x.code!=''&&x.code!='null'&&x.code){
                                    code=x.code
                                }else{
                                    if(x.isbn13==''){
                                        code=x.isbn10
                                    }else{
                                        code=x.isbn13
                                    }
                                }
                                this.setState({
                                    imgsrc,
                                    // finishupload: !0,
                                    bollowed,
                                    describe: x.describe,
                                    orders:x.orders,
                                    name: x.name,
                                    kc: x.kc,
                                    author:x.author,
                                    labels,
                                    publishhouse:x.publishhouse,
                                    code ,
                                    id:x.id,
                                    state,
                                    isrecommend,
                                    agefrom:x.agefrom,
                                    ageto:x.ageto,
                                    awards:x.awards,
                                    masters:x.masters,
                                    marsters:x.marsters,
                                    PICS: x.thumbPicPath,
                                    isbn10:x.isbn10,
                                    isbn13:x.isbn13,
                                    ismember,
                                    imgsrc,
                                    fileimgshow: !1,

                                    // detailimg:x.detaillist
                                  
            
                                                    })
                            // if (x.detaillist != null && x.detaillist.length > 0) {
                               
                            //     that.putlistdata(1, x.detaillist.split(','))
                            // }
                            // }
                            
                            // if (goods.swiperlist != null && goods.swiperlist.length > 0) {
                            //     that.putlistdata(2, res.goods.swiperlist.split(','))
                            // }
                            // if(goods.btntype.length>0){
                            //    let arr=  goods.btntype.split(',');
                            //    arr.forEach(x=>{
                            //        $('#'+x).attr('checked',true)
                            //    })
                            // }
                        // })
                        // console.log(goods)
                        // console.log(goods.detaillist)
                        var {detailimg} = this.state;
                        // console.log(detailimg);
                        
    
                        
                    } else {
                        alert('商品不存在')
                        window.location.href = './main.html'
                    }
    
                })
    
            // }
        

    }


    submit() {
        var { state,thumbPicPath, describe,orders, labels,publishhouse,author,code, bollowed,kc, name, detaillist,id,scid,awards,masters,val,isrecommend,
            agefrom,ageto,PICS,isbn10,isbn13,ismember,lbimgsrcarr,imgsrc} = this.state,imgarr = []
            , err = ''
            // console.log(awards==null,'to');
            
            if(awards==null||awards=='')awards=-1
            if(masters==null||masters=='')masters=-1
            
        //   if(detaillist.length==0) err = '请添加详情图片';
        if (!imgsrc) err = "请添加商品图片"
        if (describe.length == 0) err = '请填写描述';
        // if(awards==-1&&masters==-1){
        //     err="大奖作品或名家大师选一个"
        // }else{
        //     if(awards.length==1&&masters.length==1)err="大奖作品和名家大师只能选一个";
        // }
        if(orders==""){
            orders='1';
        }
        if(isNaN(orders)||orders<1||orders>999){
            alert('请填写1-999的整数');
            return;
        }
        if(isNaN(agefrom)||agefrom<0||agefrom>100){
            alert('请填写0-100的整数');
            return;
        }
        if(isNaN(ageto)||ageto<0||ageto>100){
            alert('请填写0-100的整数');
            return;
        }
        orders = Math.floor(orders);
        if(!kc||kc<=0)err="请填写大于0的库存数"
        if(labels==-1)err='请选择图书标签'
        if(!isbn10&&!isbn13){
            if (!code||code.length == 0) err = '请填写商品编码';
        }
        if (name.length == 0) err = '请填写姓名';
        if (err.length > 0) {
            alert(err);
            return;
        }
        imgarr = imgarr.concat(imgsrc, lbimgsrcarr)
        this.setState({awards,masters},()=>{            
            this.uploadimg(imgarr)
        })

        // detaillist = detaillist.join(',')

        // var submitdata = {
        //     thumbPicPath: PICS, bollowed, describe, name,kc, code,labels:labels+`,`+val,publishhouse,author,orders,
        //      detaillist,id,scid,awards,masters,state,isrecommend,agefrom,ageto,isbn10,isbn13,ismember
        // }
   
        // if (this.state.id > 0) submitdata['id'] = this.state.id;
        // addgoods(submitdata, res => {
        //     if (res.issuccess == 1) {
        //         alert(`${this.state.id > 0 ? '修改' : '保存'}成功`);
        //         window.location.href='./main.html'
        //     }
        // })
    }



    componentDidMount() {
        var id = GetQueryString("id");
        // console.log(id)
        var that = this;
        var {pagesize,start}=this.state;
        getawrad({pagesize,start},res => {
            if (res.issuccess == 1) {
                
                var categoryhtml = [];
                categoryhtml.push(
                    <option key={-1} value={-1}>请选择
                    </option>
                );
                res.list.forEach((x, i) => {
                    categoryhtml.push(
                        <option key={i} value={x.typename} id={x.id}>{x.typename}
                        </option>
                    )
                })
                
                that.setState({ categoryhtml });
                
            }
        })
        getmaster({pagesize,start},res => {
            if (res.issuccess == 1) {
                
                var categoryhtml2 = [];
                categoryhtml2.push(
                    <option key={-1} value={-1}>请选择
                    </option>
                );
                res.list.forEach((x, i) => {
                    categoryhtml2.push(
                        <option key={i} value={x.typename} id={x.id}>{x.typename}
                        </option>
                    )
                })
                
                that.setState({ categoryhtml2 });
                
            }
        })
        getlabellist(res => {
            if (res.issuccess == 1) {
                
                var categoryhtml1 = [];
                categoryhtml1.push(
                    <option key={-1} value={-1}>请选择
                    </option>
                );
                res.list.forEach((x, i) => {
                    // console.log(i)
                    categoryhtml1.push(
                        <option key={i} value={x.name} id={x.id}>{x.name}
                        </option>
                    )
                    // console.log(x.id)
                })
                
                that.setState({ categoryhtml1 });
              
                
            }
        })
        if (id != '0' && id != "null") {
            that.setState({id},res=>{
                console.log();
                
                this.getbook(id);
            })
        }else{
            let {bollowed,state,isrecommend,ismember}=this.state
            $(`input[name='bollowed'][value=${bollowed}]`).prop("checked", "checked");
            $(`input[name='state'][value=${state}]`).prop("checked", "checked");
            $(`input[name='isrecommend'][value=${isrecommend}]`).prop("checked", "checked");
            $(`input[name='ismember'][value=${ismember}]`).prop("checked", "checked");

        }

    }

    inputchange(prop, e) {
        // let { target } = this.state;
        // target[prop] = e.target.value
        // this.setState({ target })
        this.setState({ [prop]: e.target.value })
    }
     // 图片
     filechangeimg(e) {
        var that = this;
        var filedata = $('#file' + e)[0].files[0];
        let _name, _fileName;
        _name = $('#file' + e)[0].value;
        _fileName = _name.substring(_name.lastIndexOf(".") + 1).toLowerCase();
        if (_fileName !== "png" && _fileName !== "jpg" && _fileName !== "gif" && _fileName !== "jpeg") {
            alert("上传图片格式不正确，请重新上传");
        } else {
            if (e == '3') {
                this.setState({
                    fileimgshow: !1,
                    imgstate: ''
                })
            }
            else if (e == '1') {
                this.setState({
                    lbfileimgshow: !1,
                    lbimgstate: ''
                })
            }
            let filee = e
            var reader = new FileReader();
            reader.readAsDataURL(filedata);
            reader.onload = function (e) {
                var base64str = e.target.result;
                that.putswiperimglistdata([base64str], filee)
            }
        }
    }
    putswiperimglistdata(target, e) {
        let { imgsrc, lbimgsrc, lbimgsrcarr } = this.state;
        if (e == '3') {
            imgsrc = target[0]
            if (!isBase64(imgsrc)) {
                if (imgsrc.indexOf(`${API_HEAD}`) == -1) {
                    imgsrc = `${API_HEAD}imgs/${src}`

                }
            }
        }
        else if (e == '1') {
            let lbhtml = []
            target.forEach((x, i) => {
                lbimgsrc = x
                lbimgsrcarr.push(lbimgsrc)
                if (!isBase64(lbimgsrc)) {
                    if (lbimgsrc.indexOf(`${API_HEAD}`) == -1) {
                        lbimgsrc = `${API_HEAD}imgs/${src}`

                    }
                }
            })
            lbimgsrcarr.forEach((x, i) => {
                lbhtml.push(
                    <div className="img_warp">
                        <img src={x} className="img" />
                        <img className='closeimg' onClick={this.del_lbimg.bind(this, i)} src='./src/img_close.png' />
                    </div>
                )
            })
            this.setState({ lbhtml })
        }
        // imgarr=imgarr.concat(imgsrc,lbimgsrcarr)

        this.setState({
            imgsrc, lbimgsrc, lbimgsrcarr
        })

    }
    clickupload(e) {
        $('#file' + e).click();
    }
    del_img(e) {
        if (e == '3') {
            this.setState({
                imgsrc: '',
                fileimgshow: !0,
                imgstate: '',
            })
        }
    }
    del_lbimg(e) {

        let { lbimgsrcarr } = this.state, lbhtml = [], j = 0
        lbimgsrcarr.forEach((x, i) => {
            if (e == i) {
                lbimgsrcarr.splice(e, 1)
            }
        })
        if (lbimgsrcarr.length == 0) {
            this.setState({ lbhtml: [] })
        } else {
            lbimgsrcarr.forEach((x, i) => {
                lbhtml.push(
                    <div className="img_warp">
                        <img src={x} className="img" />
                        <img className='closeimg' onClick={this.del_lbimg.bind(this, i)} src='./src/img_close.png' />
                    </div>
                )
                // if (!isBase64(x)) {
                //     j++
                // }
                this.setState({
                    lbimgsrcarr, lbhtml
                })
            })
        }
        // if (lbimgsrcarr.length > 0) {
        //     if (j == lbimgsrcarr.length) {
        //         this.setState({ lbfileimgshow: !1, lbimgstate: 'isBase64' })
        //     }
        // }
        // if (!isBase64(url)) {
        //     let { lburlarr } = this.state
        //     lburlarr.forEach((x, i) => {
        //         if (x == url) {
        //             lburlarr.splice(i, 1)
        //         }
        //     })
        //     this.setState({ lburlarr })
        // }

    }
    // 上传图片
    uploadimg(arr) {
        let uploadimgarr = [],
            { state,thumbPicPath, describe,orders, labels,publishhouse,author,code, bollowed,kc, name, detaillist,id,scid,awards,masters,val,isrecommend,
                agefrom,ageto,PICS,isbn10,isbn13,ismember,lbimgsrcarr,imgsrc } = this.state, that = this, lbimgarr = [], imgarr = [];
        arr.forEach((x, i) => {
            if (x.indexOf(`${API_HEAD}`) == -1&&x.indexOf("http")==-1) {
                if (isBase64(x)) {
                    uploadimg(x, res => {
                        if (res.issuccess == 1) {
                            x = `${API_HEAD}imgs/${res.path}`
                            uploadimgarr.push(x)
                        } else {
                            alert(res.msg)
                            err = 1
                            return;
                        }
                    })
                }
            } else {
                uploadimgarr.push(x)
            }
        })
        console.log(uploadimgarr.length,'uploadimgarr.lengthuploadimgarr.length');
        console.log(arr.length,'arr.length');
        console.log(arr,'arr');
        
        if (uploadimgarr.length == arr.length) {
            console.log(111);
            uploadimgarr.forEach((x, i) => {
                if (i == 0) {
                    imgsrc = x.replace(`${API_HEAD}imgs/`, '')
                } else {
                    let lb = x.replace(`${API_HEAD}imgs/`, '')
                    lbimgarr.push(lb)
                }
            })

            // detaillist = detaillist.join(',')
            let detaillist = String(lbimgarr)
        var submitdata = {
            thumbPicPath: imgsrc, bollowed, describe, name,kc, code,labels:labels+`,`+val,publishhouse,author,orders,
             detaillist,id,scid,awards,masters,state,isrecommend,agefrom,ageto,isbn10,isbn13,ismember
        }
   
        if (this.state.id > 0) submitdata['id'] = this.state.id;
        console.log(submitdata,'submitdatasubmitdata');
        
        addgoods(submitdata, res => {
            if (res.issuccess == 1) {
                alert(`${this.state.id > 0 ? '修改' : '保存'}成功`);
                window.location.href='./main.html'
            }else {
                alert(res.msg)
            }
        })
        }
    }
    
    render() {
        let {imgsrc,lbhtml} = this.state;
        //  <img style={{display:this.state.thumbPicPath.length>0?"block":"none"}} src={this.state.thumbPicPath} className="img-responsive"  /> 

        return (
            <div className="breadLinebox">
                {/* <Modal content='确定删除吗？' click={this.confirmdel.bind(this)} /> */}
                <div className='content_wrap panel-default content_wrap'>
                    <div className='breadLine '>
                        当前位置 > 图书管理 > {this.state.id == 0 ? "新建" : "编辑"}图书
                    </div>

                    <div className="content form">
                        <div className="formtitle">
                            <p>{this.state.id > 0 ? "编辑" : "新建"}</p>
                        </div>
                        <div className="formbox">
                        {/* <input id='name' onChange={this.inputchange.bind(this, 'price')} value={price} type="text" placeholder='请输入商品原价' className="input" /> */}
                            <div className="formcontent">
                                <div className="input-group">
                                    <span className="input-group-addon">图书名称</span>
                                    <input id='name' onChange={this.inputchange.bind(this,'name')} value={this.state.name} type="text" placeholder='请输入图书名称'  className="input" />
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">图书编码</span>
                                    <input id='name' onChange={this.inputchange.bind(this,'code')} value={this.state.code} type="text" placeholder='请输入图书条形码'  className="input" />
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">图书作者</span>
                                    <input id='name' onChange={this.inputchange.bind(this,'author')} type="text" value={this.state.author} placeholder='请输入图书作者'  className="input" />
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">图书出版社</span>
                                    <input id='name' onChange={this.inputchange.bind(this,'publishhouse')} type="text" value={this.state.publishhouse} placeholder='请输入图书出版社'  className="input" />
                                </div>
                                 <div className="input-group">
                                    <span className="input-group-addon">图书标签</span>
                                    <div className="mallradiobox" >
                                        <select value={this.state.labels} onChange={this.inputchange.bind(this,'labels')} className="form-control select">
                                            {this.state.categoryhtml1}
                                        </select>
                                    </div>
                                </div>
                                <div className="input-group" style={{display:"none"}}>
                                    <span className="input-group-addon">二级分类</span>
                                    <div className="mallradiobox" >
                                        <select value={this.state.val} onChange={this.inputchange.bind(this,'val')} className="form-control select">
                                        {this.state.subcategoryhtml}
                                        </select>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">图书简介</span>
                                    <textarea id='describe' onChange={this.inputchange.bind(this,'describe')} value={this.state.describe} className="textarea" placeholder='请输入图书简介' rows="3"></textarea>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">库存</span>
                                    <input onChange={this.inputchange.bind(this,'kc')} type="text" value={this.state.kc} placeholder='请输入图书库存' className="input" />
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">排序</span>
                                    <input onChange={this.inputchange.bind(this,'orders')} type="text" value={this.state.orders} placeholder='请输入图书排序' className="input" />
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">图书状态</span>
                                    <div className="radiobox" onChange={this.inputchange.bind(this, 'bollowed')}>
                                        <div className="radio"><input type="radio" name="bollowed" id="inlineCheckbox1" value="0"/><label for="inlineCheckbox1"></label><span>可借阅</span></div>
                                        <div className="radio"><input type="radio" name="bollowed" id="inlineCheckbox2" value="1" /><label for="inlineCheckbox2"></label><span>不可借阅</span></div>
                                        <div className="radio"><input type="radio" name="bollowed" id="inlineCheckbox3" value="2" /><label for="inlineCheckbox3"></label><span>借完</span></div>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">图书状态</span>
                                    <div className="radiobox" onChange={this.inputchange.bind(this, 'state')}>
                                        <div className="radio"><input type="radio" name="state" id="stateCheckbox1" value="0"/><label for="stateCheckbox1"></label><span>上架</span></div>
                                        <div className="radio"><input type="radio" name="state" id="stateCheckbox2" value="1" /><label for="stateCheckbox2"></label><span>下架</span></div>
                                        <div className="radio"><input type="radio" name="state" id="stateCheckbox3" value="2" /><label for="stateCheckbox3"></label><span>售完</span></div>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">是否设为推荐</span>
                                    <div className="radiobox" onChange={this.inputchange.bind(this, 'isrecommend')}>
                                        <div className="radio"><input type="radio" name="isrecommend" id="isrecommendbox1" value="0"/><label for="isrecommendbox1"></label><span>未推荐</span></div>
                                        <div className="radio"><input type="radio" name="isrecommend" id="isrecommendbox2" value="1" /><label for="isrecommendbox2"></label><span>推荐</span></div>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">是否会员观看</span>
                                    <div className="radiobox" onChange={this.inputchange.bind(this,'ismember')}>
                                        <div className="radio"><input type="radio" name="ismember" value="T" id="ismember1" /><label for="ismember1"></label><span>是</span></div>
                                        <div className="radio"><input type="radio" name="ismember" value="F" id="ismember2" /><label for="ismember2"></label><span>否</span></div>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">年龄专区</span>
                                    <div>
                                            从<input type="text"  onChange={this.inputchange.bind(this,'agefrom')} value={this.state.agefrom} style={{width:50}} className="input"/> 岁
                                            ~到<input type="text"  onChange={this.inputchange.bind(this,'ageto')} value={this.state.ageto} style={{width:50}}  className="input"/> 岁
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">大奖作品</span>
                                    <div className="mallradiobox" >
                                        <select  value={this.state.awards} onChange={this.inputchange.bind(this,'awards')} className="form-control">
                                            {this.state.categoryhtml}
                                        </select>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="input-group-addon">名家大师</span>
                                    <div className="mallradiobox" >
                                        <select value={this.state.masters} onChange={this.inputchange.bind(this,'masters')} className="form-control select">
                                            {this.state.categoryhtml2}
                                        </select>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <span className="label input-group-addon">封面图</span>
                                    <input onChange={this.filechangeimg.bind(this, '3')} type='file' id='file3' style={{ display: "none" }} />
                                    <div className='detail_btns'>
                                        <img className='fileimg' src={Constant.UPLOADBTN} onClick={this.clickupload.bind(this, '3')} style={{ display: this.state.fileimgshow ? "" : "none" }} />
                                        <div className="img_warp" style={{ display: this.state.fileimgshow ? "none" : "" }}>
                                            <img src={imgsrc} className="img" />
                                            <img className='closeimg' onClick={this.del_img.bind(this, '3')} src='./src/img_close.png' style={{ display: this.state.fileimgshow ? "none" : "" }} />
                                        </div>
                                    </div>
                                </div>
                                <div className="input-group">
                                    <p className="lbtit"><span className="label input-group-addon">详情图</span></p>
                                    <input onChange={this.filechangeimg.bind(this, '1')} type='file' id='file1' style={{ display: "none" }} />
                                    <div className='detail_btns lbimgbox'>
                                        <div>
                                            {lbhtml}
                                        </div>
                                        <img className='fileimg' src={Constant.UPLOADBTN} onClick={this.clickupload.bind(this, '1')} />
                                    </div>
                                </div>

                            </div>
                            <div className="submitbox">
                                <button type="button" onClick={this.submit.bind(this)} className="submitbutton cursor">提交</button>
                                {/* <button type="button" onClick={this.torole.bind(this)} className="submitbutton cursor" style={{ marginLeft: '100' }}>返回</button> */}
                            </div>

                        </div>
                    </div>
                </div>
            </div>

        )
    }
}


ReactDOM.render(
    <div>
        <TopLine />
        {/* <LeftMenu code='2' /> */}
        <LeftMenu code='books' />
        <Book />
    </div>
    , $('.container')[0]
)